package com.r2coding.domain.strategy.repository;

import com.r2coding.domain.strategy.model.entity.StrategyAwardEntity;
import com.r2coding.domain.strategy.model.entity.StrategyEntity;
import com.r2coding.domain.strategy.model.entity.StrategyRuleEntity;
import com.r2coding.domain.strategy.model.valobj.StrategyAwardRuleModelVO;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

/**
 * 抽奖概率仓储服务
 *
 * @author caolx
 * @date 2025/7/25 7:25
 */
public interface IStrategyRepository {

    /**
     * 查询策略ID下的策略奖品列表
     *
     * @param strategyId 策略ID
     * @return 抽奖策略奖品实体列表
     */
    List<StrategyAwardEntity> queryStrategyAwardList(Long strategyId);

    /**
     * 缓存策略奖品概率查找表缓存
     *
     * @param strategyId                          策略ID
     * @param rateRange                           概率范围
     * @param shuffleStrategyAwardSearchRateTable 奖品概率查找表
     */
    void storeStrategyAwardSearchRateTable(Long strategyId, BigDecimal rateRange, Map<Integer, Integer> shuffleStrategyAwardSearchRateTable);

    /**
     * 缓存 策略奖品权重概率查找表
     *
     * @param strategyId                          策略ID
     * @param ruleWeight                          策略权重
     * @param rateRange                           概率范围
     * @param shuffleStrategyAwardSearchRateTable 奖品概率查找表
     */
    void storeStrategyWeightAwardSearchRateTable(Long strategyId, Integer ruleWeight, BigDecimal rateRange, Map<Integer, Integer> shuffleStrategyAwardSearchRateTable);

    /**
     * 获取策略ID对应的奖品概率范围
     *
     * @param strategyId 策略ID
     * @return 策略ID对应的奖品概率范围
     */
    Integer getRateRange(Long strategyId);

    /**
     * 获取策略ID对应的奖品概率范围
     *
     * @param strategyId 策略ID
     * @param ruleWeight 权重
     * @return 策略ID对应的奖品概率范围
     */
    Integer getRuleWeightRateRange(Long strategyId, Integer ruleWeight);

    /**
     * 获取随机概率数对应的奖品ID
     *
     * @param strategyId 策略ID
     * @param rateKey    随机概率数
     * @return 奖品ID
     */
    Integer getStrategyAwardAssemble(Long strategyId, Integer rateKey);

    /**
     * 获取随机概率数对应的奖品ID
     *
     * @param strategyId 策略ID
     * @param ruleWeight 权重值
     * @param rateKey    随机概率数
     * @return 奖品ID
     */
    Integer getStrategyWeightAwardAssemble(Long strategyId, Integer ruleWeight, Integer rateKey);

    /**
     * 查询抽奖策略 充血实体
     *
     * @param strategyId 策略ID
     * @return 抽奖策略 充血实体
     */
    StrategyEntity queryStrategyEntity(Long strategyId);

    /**
     * 查询抽奖策略规则模型配置
     *
     * @param strategyId 策略ID
     * @param ruleModel  抽奖策略规则模型
     * @return 抽奖策略规则模型配置
     */
    StrategyRuleEntity queryStrategyRuleEntity(Long strategyId, String ruleModel);

    /**
     * 查询抽奖规则配置值
     *
     * @param strategyId 策略ID
     * @param awardId    奖品ID
     * @param ruleModel  规则模型
     * @return 规则模型 配置值
     */
    String queryStrategyRuleValue(Long strategyId, Integer awardId, String ruleModel);

    /**
     * 查询策略奖品配置的校验规则模型
     *
     * @param strategyId 策略ID
     * @param awardId    奖品ID
     * @return 策略奖品配置的校验规则模型
     */
    StrategyAwardRuleModelVO queryStrategyAwardRuleModelVO(Long strategyId, Integer awardId);
}
